package logic

import (
	"context"
	"day1/video/rpc/internal/models"
	"net/http"

	"day1/video/rpc/internal/svc"
	"day1/video/rpc/pb/video"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *video.UpdateRequest) (*video.UpdateResponse, error) {
	// todo: add your logic here and delete this line
	err := models.Register(models.File{
		ProjectId: 1,
		UserId:    1,
		Name:      in.Name,
		Path:      in.Path,
		Version:   int(in.Version),
	})
	//文件回滚
	
	if err != nil {
		return &video.UpdateResponse{
			Code: -1,
			Msg:  err.Error(),
		}, nil
	}
	return &video.UpdateResponse{
		Code: http.StatusOK,
		Msg:  "success",
	}, nil
}
